<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜品增加</title>
<link rel="stylesheet" href="../../../files/css/layui.css" media="all">
<style type="text/css">
#goodsImg {
	position: relative;
	left: 110px;
}
</style>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>菜品增加列表</legend>
	</fieldset>

	<form class="layui-form" action="../../../menu/addOrUpdate.action"
		enctype="multipart/form-data" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">菜品类型</label>
			<div class="layui-input-inline">
				<select name="mtId" lay-verify="required" lay-filter="mtId" id="mtId">
					<option value="">直接选择或搜索选择</option>
				<select>
			</div>
			<div class="layui-input-inline">
	           <select name="cate2" id="cate2">
	               <option value="" selected>二级分类</option>
	           </select>
	       </div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">菜品名称</label>
			<div class="layui-input-inline">
				<input type="text" name="menuName" required lay-verify="required"
					maxlength="12" placeholder="请输入菜品名称" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">菜品单价</label>
			<div class="layui-input-inline">
				<input type="text" name="menuMoney" required lay-verify="required"
					maxlength="12" placeholder="请输入菜品单价" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">菜品销量</label>
			<div class="layui-input-inline">
				<input type="number" name="sales" required lay-verify="required"
					maxlength="12" placeholder="请输入菜品销量" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">菜品简介</label>
			<div class="layui-input-inline">
				<input type="text" name="introduce" required lay-verify="required"
					maxlength="12" placeholder="请输入菜品简介" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否有效</label>
			<div class="layui-input-inline">
				<select name="isva" required="required">
					<option value="0">无效</option>
					<option value="1">有效</option>
				</select>
			</div>
		</div>
		<!-- <div class="layui-form-item">
			<label class="layui-form-label">加入时间</label>
			<div class="layui-input-inline">
				<input type="date" name="optime" required
					lay-verify="required" maxlength="12" placeholder="请输入加入时间" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div> -->

		<div class="layui-form-item">
			<label class="layui-form-label">操作人</label>
			<div class="layui-input-inline">
				<input type="text" name="oper" required lay-verify="required"
					maxlength="12" placeholder="请输入操作人" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否排序</label>
			<div class="layui-input-inline">
				<input type="text" name="sort" required lay-verify="required"
					maxlength="12" placeholder="请输入排序号码" autocomplete="off"
					class="layui-input" class="layui-icon">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="submit" class="layui-btn" lay-submit=""
					lay-filter="imgAdd" value="立即增加">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>



	<script src="../../../files/js/layui.js"></script>
	<script type="text/javascript" src="../../../files/js/jquery.min.js"></script>
	<script>
		layui.use('form', function() {
			var form = layui.form, layer = layui.layer, $ = layui.$;
			$.ajax({
				  url:"../../../shop/findAll.action",
			  	  data:{action:"findAlls"},
			  	  success:function(msg){
			  		 //alert(123);
			  		 
			  		 for(var i=-0;i<msg.length;i++){
			  			$("#mtId").append("<option value="+msg[i].shopId+">"+msg[i].shopName+"</option>");
			  			form.render();
			  			
			  		 }
			  	  },
			  	  dataType:"JSON"
			  })

			form.on('submit(imgAdd)', function() {
				layer.msg('数据加载中', {
					icon : 1,
					time : 10
				//2秒关闭（如果不配置，默认是3秒）
				}, function() {
					//进行渲染 
					parent.location.reload(); // 父页面刷新
				});
			});
			form.on("select(mtId)",function () {
				  alert(123);
				  $("#cate2").html("");
			      var optionstring = "";
			      var cate1 = $("#mtId").val();
			      var url = "../../../menutype/findByIds.action";
			  	var data = {"shopId" : cate1 };
			  	$.post(url, data, function(msg) {
			  		alert(msg.length);
			  		if(msg.length>0){
			  			$("#cate2").val("");
				   		 for(var i=-0;i<msg.length;i++){
				   			$("#cate2").append("<option value="+msg[i].mtId+">"+msg[i].mtName+"</option>");
				   			form.render();
				   		 }
			  		}else{
			  			//document.getElementById("cate2").innerHTML=null;
			  			$("#cate2").val("");
			  			$("#cate2").append("<option>暂无</option>");
			  			layer.msg('暂无下级');
			  			form.render();
			  		}
			  		
			      }, "json");
			  })
		});
	</script>

</body>
</html>